﻿using IdentityServer4.Models;
using IdentityServer4.Test;
using System.Collections.Generic;
using System.Linq;
using YXY.Identity.Validator;
using static IdentityServer4.IdentityServerConstants;
using static System.Net.WebRequestMethods;

namespace YXY.Identity
{
    public class OAuthMemoryData
    {
        /// <summary>
        /// 这个ApiResource参数就是我们Api
        /// Api资源 静态方式定义
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetApiResources()
        {
            return new List<ApiResource>
           {
                new ApiResource(OAuthConfig.UserApi.ApiName,OAuthConfig.UserApi.ApiName)
                {

                },
           };
        }
        public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                 new Client()
                {
                    ClientId =OAuthConfig.UserApi.ClientId,
                    AllowedGrantTypes = new List<string>()
                    {
                        GrantTypes.ClientCredentials.FirstOrDefault(),
                        GrantTypes.ResourceOwnerPassword.FirstOrDefault(),//Resource Owner Password模式
                        GrantTypeConstants.ResourceWeixinOpen,//新增的自定义微信客户端的授权模式
                    },
                    ClientSecrets = 
                     {
                         new Secret(OAuthConfig.UserApi.Secret.Sha256()) 
                     },
                    AllowedScopes= 
                     {
                         OAuthConfig.UserApi.ApiName,
                         StandardScopes.OfflineAccess//如果要获取refresh_tokens ,必须在scopes中加上OfflineAccess
                     },
                    AccessTokenLifetime = OAuthConfig.ExpireIn,
                    AllowOfflineAccess = true,//如果要获取refresh_tokens ,必须把AllowOfflineAccess设置为true
  
                },
            };
        }

        public static IEnumerable<ApiScope> ApiScopes =>
             new ApiScope[] { new ApiScope("api") };

        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId()
            };
        }
        /// <summary>
        /// 测试的账号和密码
        /// </summary>
        /// <returns></returns>
        public static List<TestUser> GetTestUsers()
        {
            return new List<TestUser>
            {
                new TestUser()
                {
                     SubjectId = "1",
                     Username = "test",
                     Password = "123"
                }
            };
        }
        public static List<ParamConstants> GetWeiXinOpenIdTestUsers()
        {
            return new List<ParamConstants>
            {
                new ParamConstants()
                {
                    
                }
            };
        }

    }
}
